package com.easyidea.its.web.action.department;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import com.easyidea.its.domain.model.system.Department;
import com.easyidea.its.domain.model.system.PassPort;
import com.easyidea.its.facade.department.PassPortMgr;
import com.easyidea.its.util.ItsConstants;
import com.easyidea.its.util.PageUtil;
import com.easyidea.its.util.Result;
import com.easyidea.its.util.SessionUtil;
import com.easyidea.its.web.action.base.ItsBaseAction;


public class PassPortAction extends ItsBaseAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = 2703853391641951842L;

	private PassPortMgr passPortMgr;
	
	private PassPort passPort;
	private Integer id;
	private Collection<Department> allDepartments;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@SuppressWarnings("unchecked")
	public String passPortList() {	
		if(passPort == null) {
			passPort = new PassPort();
		}		
		int totalRecords = passPortMgr.getPassPortsCount(passPort);
		if (totalRecords > 0) {
			List<PassPort> records = passPortMgr.getPassPorts(passPort, (currentPage - 1) * pageSize,
					pageSize);
			result = PageUtil.createResult(pageSize, currentPage, totalRecords, records);
		} else {
			result = PageUtil.createResult(pageSize, currentPage, 0, new ArrayList());
		}
		return SUCCESS;
	}
	
	public String passPortAdd() {
		if(passPort == null) {
			passPort = new PassPort();
		}
		allDepartments = passPortMgr.getAllDepartments();
		return SUCCESS;
	}
	public String passPortEdit() {
		
		allDepartments = passPortMgr.getAllDepartments();
		passPort = passPortMgr.getPassPortById(id);
		return SUCCESS;
	}
	public String  saveOrUpdate() {
		boolean ret = passPortMgr.saveOrUpdate(passPort);
		if (!ret) {
			errorMsg = "卡口名称存在重复！";
			return INPUT;
		}
		 getSession().setAttribute("successMsg", "save.success");
		return SUCCESS;
	}
	public String passPortDel() {
		
		 try{
			 passPortMgr.removePassPortById(id) ;
			 getSession().setAttribute("successMsg", "delete.success");
		 }catch (Exception e) {
			 getSession().setAttribute("successMsg", "delete.passpor.failure"); 
		  
		 } 
		return SUCCESS;
	}

	private Result<PassPort> result;

	public PassPortMgr getPassPortMgr() {
		return passPortMgr;
	}

	public void setPassPortMgr(PassPortMgr passPortMgr) {
		this.passPortMgr = passPortMgr;
	}

	public PassPort getPassPort() {
		return passPort;
	}

	public void setPassPort(PassPort passPort) {
		this.passPort = passPort;
	}

	public Result<PassPort> getResult() {
		return result;
	}

	public void setResult(Result<PassPort> result) {
		this.result = result;
	}

	public Collection<Department> getAllDepartments() {
		return allDepartments;
	}

	public void setAllDepartments(Collection<Department> allDepartments) {
		this.allDepartments = allDepartments;
	}
	

}
